from file_define import FileReader, TextFileRecord, JsonFileRecord
from data_file import Record
from pyecharts.charts import Bar
from pyecharts.options import *
from pyecharts.globals import ThemeType

text_file_reader = TextFileRecord("D:/2011年1月销售数据.txt")
json_file_reader = JsonFileRecord("D:/2011年2月销售数据JSON.txt")

jan_data = text_file_reader.read_data()
feb_data = json_file_reader.read_data()

# 将二月份的数据合并为1个list来存储
all_data = jan_data + feb_data
# 开始数据计算
data_dict = {}
for record in all_data:
    if record.date in data_dict.keys():
        data_dict[record.date] += record.money
    else:
        data_dict[record.date] = record.money

# 可视化图标开发
bar = Bar(init_opts=InitOpts(theme=ThemeType.LIGHT))

bar.add_xaxis(list(data_dict.keys()))
bar.add_yaxis("销售额", list(data_dict.values()), label_opts=LabelOpts(is_show=False))
bar.set_global_opts(
    title_opts=TitleOpts(title="每日销售额")
)
bar.render("每日销售额柱状图.html")
